use master;
go
drop database atmsystemsangson;
go
create database atmsystemsangson;
go
use atmsystemsangson;
go
--bang tblAdmin chua thong tin dang nhap cua Admin
-- de giup dang nhap vao giao dien Admin de chinh sua tao moi thong tin User
create table tblAdmin(
fldID_Admin nvarchar(50),	
fldPassword_Admin nvarchar(50) not null,
constraint pk_tblAdmin primary key (fldID_Admin)
);
go
--bang tblCustomer luu thong tin Customer
create table tblCustomer(
fldID_Customer nvarchar(50), --ma khach hang
fldFull_Name nvarchar(50)not null, --Ten day du cua khach hang
fldID_Number nvarchar(50)not null,	--So chung minh thu nhan dan cua khach hang
fldSex bit not null, --gioi tinh cua khach hang
fldBirth datetime not null, --ngay sinh cua khach hang
fldAddress nvarchar(50) not null, --dia chi cua khach hang
fldPhone nvarchar(50) not null, --so dien thoai cua khach hang
fldEmail nvarchar(50) not null, -- dia chi email cua khach hang
constraint pk_tblCustomer primary key (fldID_Customer)
);
go
--bang tblAccount chua thong tin tai khoan cua khach hang
create table tblAccount(
fldID_Account nvarchar(50), --ma tai khoan
fldPIN nchar(4) not null, --so PIN
fldID_Customer nvarchar(50) not null, --ma khach hang
fldCurrency int not null, --so tien trong tai khoan cua khach hang
fldStatus bit default 1, --tinh trang tai khoan 
constraint pk_tblAccount primary key (fldID_Account),
constraint fk_tblAccount_tblCustomer foreign key (fldID_Customer) references tblCustomer(fldID_Customer)
);
go
--bang tblTransaction luu thong tin giao dich
create table tblTransaction(
fldID_Transaction nvarchar(50) constraint pk_tblTransaction primary key, -- ma giao dich 
fldID_Account nvarchar(50)not null, --ma tai khoan
fldDate datetime default getdate(), --ngay giao dich
fldType_Transaction nvarchar(50) not null, --kieu giao dich
fldCurrency_Before int not null, --tien truoc giao dich
fldCurrency_Transaction int default 0, --tien giao dich
fldCurrency_Last int not null, --tien sau giao dich
constraint fk_tblTransaction_tblAccount foreign key (fldID_Account) references tblAccount(fldID_Account)
);
go

select * from tblAdmin;
go
select * from tblCustomer;
go
select * from tblAccount;
go
select * from tblTransaction;
go
select tblCustomer.fldID_Customer from tblCustomer;


